﻿package com.moa;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.pc.util.http.PCHttp;
/*******************************************************************************
 * 
 * @author zdw
 * 
 */
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		// �õ��ͻ��˴�������(�û��������)
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		GetURLServlet.name = username;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		
		int method = 1;
		
		String login =  PCHttp.login(username,"USERNAME="+username+"&PASSWORD="+password,0,"/logincheck.php","GBK");
		System.out.println("login=="+login);
		 if(login.indexOf("用户名或密码错误")==-1){
			 dos.writeUTF("true");
			 System.out.println("恭喜你，登陆成功！");
		 }else{
			 dos.writeUTF("false");
			 System.out.println("登陆失败！");
		 }
		
//		if ("moa".equals(username) && "admin".equals(password))
//		{���
//			dos.writeUTF("true");
//		} else
//		{���
//			dos.writeUTF("false");
//		}

		byte[] data = baos.toByteArray();
		response.setStatus(HttpServletResponse.SC_OK);
		response.setContentLength(data.length);
		response.setContentType("application/octet-stream");
		OutputStream os = response.getOutputStream();
		os.write(data);
		os.close();
	}

}
